//
//  NSDecimalNumber+Add.h
//  ITC_iOS
//
//  Created by Benz.L on 13/09/2018.
//  Copyright © 2018 Benz.L. All rights reserved.
//
/*
参考
https://www.jianshu.com/p/206708848931
https://www.jianshu.com/p/946c4c4aff33
 */

#import <Foundation/Foundation.h>

@interface NSString(NSDecimalNumber)
- (NSDecimalNumber *)decimalNumber;
@end



typedef NSDecimalNumber *(^OperBlock)(NSDecimalNumber *operand);
typedef NSDecimalNumber *(^RoundBlock)(NSUInteger scale);
typedef NSDecimalNumber *(^RoundModeBlock)(NSUInteger scale, NSRoundingMode mode);
typedef BOOL (^CompareBlock)(NSDecimalNumber *operand);
typedef BOOL (^NANBlock)(void);
typedef NSString *(^StringBlock)(NSUInteger scale);

@interface NSDecimalNumber(ChainOperation)

// 运算
- (OperBlock)add;    // +
- (OperBlock)sub;    // -
- (OperBlock)mult;   // *
- (OperBlock)div;    // /
- (RoundBlock)round; // 四舍五入
- (RoundModeBlock)roundMode; // 四舍五入

// 比较
- (CompareBlock)g;  // >
- (CompareBlock)ge; // >=
- (CompareBlock)eq; // ==
- (CompareBlock)l;  // <
- (CompareBlock)le; // <=
- (CompareBlock)ne; // !=

// 判断
- (NANBlock)isNAN;

// 字符串
- (StringBlock)stringScale; // 输出字符串，可指定小数位数scale

@end


@interface NSDecimalNumber(Operation)

- (NSDecimalNumber *)add:(NSDecimalNumber *)decimal; // +
- (NSDecimalNumber *)sub:(NSDecimalNumber *)decimal; // -
- (NSDecimalNumber *)mult:(NSDecimalNumber *)decimal;// *
- (NSDecimalNumber *)div:(NSDecimalNumber *)decimal; // /
- (NSDecimalNumber *)round:(NSUInteger)digits; // 四会五入
- (BOOL)isNan;

@end
